/*

    This file is part of Blue Violin.

    Blue Violin is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Blue Violin is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero Public License for more details.

    You should have received a copy of the GNU Affero Public License
    along with Blue Violin.  If not, see <http://www.gnu.org/licenses/>.

    Blue Violin  Copyright (C) 2008  Blue Violin, Inc. & Josh Watts <josh.watts@blueviolin.org>
	For more information, visit http://www.blueviolin.org/

    This program comes with ABSOLUTELY NO WARRANTY.

*/

function CreateAccount()
{
}


CreateAccount.prototype.keyPress = function()
{
	if (27 == window.event.keyCode)
	{
		this.cancel();
	}
	
};

	
CreateAccount.prototype.create = function()
{
	var txtEmail = $get("txtEmail");
	var txtPassword1 = $get("txtPassword1");
	var txtPassword2 = $get("txtPassword2");

	if ("" == txtEmail.value)
	{
		alert("The Magic 8 Ball says: Don't be afraid to give us your email address.");
		return;
	}
	if ("" == txtPassword1.value &&
		"" == txtPassword2.value)
	{
		alert("Every good secret deserves a password - give us one to keep yours.");
		return;
	}
	if (txtPassword1.value != txtPassword2.value)
	{
		alert("Yo! Your passwords don't match. Fix 'em and try again.");
	}
	else
	{
		window.dialogArguments.email = txtEmail.value;
		window.dialogArguments.password = txtPassword1.value;
		window.close();
	}
	
};
	

CreateAccount.prototype.cancel = function()
{
	window.dialogArguments.email = null;
	window.dialogArguments.password = null;

	window.close();
};


var oCreateAccount = new CreateAccount();

function CreateAccountBodyLoad()
{
	var txtEmail = $get("txtEmail");
	var txtPassword1 = $get("txtPassword1");
	var txtPassword2 = $get("txtPassword2");
	
	document.body.attachEvent("onkeypress",
							  $createDelegate(oCreateAccount, oCreateAccount.keyPress));
	
	$get("btnCreate").attachEvent("onclick",
								  $createDelegate(oCreateAccount, oCreateAccount.create));
	$get("btnCancel").attachEvent("onclick",
								  $createDelegate(oCreateAccount, oCreateAccount.cancel));
	
}
